#ifndef MUSICPROGRESSBAR_H
#define MUSICPROGRESSBAR_H

#include <QObject>
#include <QWidget>
#include <QMediaPlayer>
#include <QMouseEvent>
#include <QPixmap>
#include <QPainter>
class MusicProgressBar : public QWidget
{
    Q_OBJECT
public:
    explicit MusicProgressBar(QWidget *parent = nullptr);
    void setMediaPlayer(QMediaPlayer *player); // 关联媒体播放器
    void setSliderPixmap(const QPixmap &pixmap); // 设置滑块图标

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void updateProgressFromMouse(int x);
signals:
    void progressChanged(int value); // 进度变化信号
private:
    QMediaPlayer *m_player = nullptr;
    int m_progress = 0; // 0-100 的进度值
    QPixmap m_sliderPix; // 滑块图标
    bool m_isDragging = false; // 判断是否正在拖动滑块
};

#endif // MUSICPROGRESSBAR_H
